package com.ycd.Servlet;

import com.ycd.Entity.UserEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 首页展示
 * @Author ycd
 * @Date : 2022/3/16 17:12
 * @Version : 1.0
 */
@WebServlet("/index.h")
public class ShowIndexHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");


        //从session对象中获取user对象

        UserEntity userentity= (UserEntity) req.getSession().getAttribute("user");

        if(userentity==null){
            //如果用户为空 ，说明用户没有登录  ，那么页面跳转到登录页面
            resp.sendRedirect("login.h?type=3");
            return;
        }

        req.getRequestDispatcher("WEB-INF/page/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}